package com.example.controller;

import com.example.pojo.*;
import com.example.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class AdminController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/admin/teacher")
    public Result getTeacher(@RequestParam(defaultValue = "0") Integer page,
                             @RequestParam(defaultValue = "10") Integer size,
                             String name, String username, Integer gradeClassId, String object) {

        log.info("接收到的参数{},{},{},{},{},{},", page, size, name, username, gradeClassId, object);
        UserPageBean userPageBean = adminService.selectAll(page, size, name, username, gradeClassId, object);

        return Result.success(userPageBean);
    }


    @GetMapping("/admin/parent")
    public Result getParent(@RequestParam(defaultValue = "0") Integer page,
                            @RequestParam(defaultValue = "10") Integer size,
                            String name, String username, Integer gradeClassId, String studentName) {
        log.info("接收到的参数{},{},{},{},{},{},", page, size, name, username, gradeClassId, studentName);
        UserPageBean userPageBean = adminService.getParent(page, size, name, username, gradeClassId, studentName);
        return Result.success(userPageBean);
    }

    @GetMapping("/admin/student")
    public Result getStudent(@RequestParam(defaultValue = "0") Integer page,
                             @RequestParam(defaultValue = "10") Integer size,
                             String name, Integer gender, Integer gradeClassId) {
        log.info("接收到的参数{},{},{},{},{},", page, size, name, gender, gradeClassId);
        UserPageBean userPageBean = adminService.getStudent(page, size, name, gender, gradeClassId);
        return Result.success(userPageBean);
    }


    @PutMapping("/admin/teacher/update")
    public Result updateTeacher(@RequestBody Teacher teacher) {
        adminService.updateTeacher(teacher);
        return Result.success();
    }

    @PutMapping("/admin/parent/update")
    public Result updateParent(@RequestBody Patriarch patriarch) {
        adminService.updateParent(patriarch);
        return Result.success();
    }


    @PutMapping("/admin/student/update")
    public Result updateStudent(@RequestBody Student student) {
        adminService.updateStudent(student);
        return Result.success();
    }

    @PutMapping("/admin/teacher/add")
    public Result addTeacher(@RequestBody Teacher teacher) {
        adminService.addTeacher(teacher);
        return Result.success();
    }

    @PutMapping("/admin/parent/add")
    public Result addParent(@RequestBody Patriarch patriarch) {
        adminService.addParent(patriarch);
        return Result.success();
    }

    @PutMapping("/admin/student/add")
    public Result addStudent(@RequestBody Student student) {
        adminService.addStudent(student);
        return Result.success();
    }


    @GetMapping("/admin/plan")
    public Result getAllPlan(@RequestParam(defaultValue = "0") Integer page,
                             @RequestParam(defaultValue = "10") Integer size,
                             String title, String content, String teacherName) {


        log.info("接收到的查询条件：{},{},{},{},{}", page, size, title, content, teacherName);
        WorkPageBean workPageBean = adminService.getAllPlan(page, size, title, content, teacherName);

        return Result.success(workPageBean);

    }

    @PutMapping("/admin/plan/update")
    public Result updatePlan(@RequestBody Plan plan) {
        log.info("审核通过对象：{}", plan);
        adminService.updatePlan(plan);
        return Result.success();
    }

    @PutMapping("/admin/plan/add")
    public Result addPlan(@RequestBody Plan plan) {
        log.info("添加计划对象：{}", plan);
        adminService.addPlan(plan);
        return Result.success();
    }

    @PostMapping("/admin/plan/delet")
    public Result delPlan(@RequestBody Plan plan) {
        log.info("删除计划对象{}", plan);
        adminService.delPlan(plan);
        return Result.success();
    }

    @GetMapping("/admin/progress")
    public Result getAllProgress(@RequestParam(defaultValue = "0") Integer page,
                                 @RequestParam(defaultValue = "10") Integer size,
                                 String title, String content, String teacherName) {


        log.info("接收到的查询条件：{},{},{},{},{}", page, size, title, content, teacherName);
        WorkPageBean workPageBean = adminService.getAllProgress(page, size, title, content, teacherName);

        return Result.success(workPageBean);

    }

    @PutMapping("/admin/progress/update")
    public Result updateProgress(@RequestBody Progress progress) {
        log.info("审核进度对象：{}", progress);
        adminService.updateProgress(progress);
        return Result.success();
    }

    @PutMapping("/admin/progress/add")
    public Result addProgress(@RequestBody Progress progress) {
        log.info("添加进度对象：{}", progress);
        adminService.addProgress(progress);
        return Result.success();
    }

    @PostMapping("/admin/progress/delet")
    public Result delProgress(@RequestBody Progress progress) {
        log.info("删除进度对象{}", progress);
        adminService.delProgress(progress);
        return Result.success();
    }

    @GetMapping("/admin/homeWork")
    public Result getAllHomeWork(@RequestParam(defaultValue = "0") Integer page,
                                 @RequestParam(defaultValue = "10") Integer size,
                                 String title, String content, String teacherName) {


        log.info("接收到的查询条件：{},{},{},{},{}", page, size, title, content, teacherName);
        WorkPageBean workPageBean = adminService.getAllHomeWork(page, size, title, content, teacherName);

        return Result.success(workPageBean);

    }

    @GetMapping("/admin/homeWork/selectDate/{id}")
    public Result seletDateHomeWork(@PathVariable Integer id) {
        log.info("查看作业对象详情：{}", id);
        List<StudentHomeWork> studentHomeWorkList = adminService.seletDateHomeWork(id);
        return Result.success(studentHomeWorkList);
    }

    @PutMapping("/admin/homeWork/add")
    public Result addHomeWork(@RequestBody HomeWork homeWork) {
        log.info("添加计划对象：{}", homeWork);
        adminService.addHomeWork(homeWork);
        return Result.success();
    }

    @PostMapping("/admin/homeWork/delet")
    public Result delHomeWork(@RequestBody HomeWork homeWork) {
        log.info("删除计划对象{}", homeWork);
        adminService.delHomeWork(homeWork);
        return Result.success();
    }


    @GetMapping("/admin/task")
    public Result getAllTask(@RequestParam(defaultValue = "0") Integer page,
                             @RequestParam(defaultValue = "10") Integer size,
                             String title, String content, String teacherName) {

        log.info("接收到的查询条件：{},{},{},{},{}", page, size, title, content, teacherName);
        WorkPageBean workPageBean = adminService.getAllTask(page, size, title, content, teacherName);

        return Result.success(workPageBean);

    }

    @GetMapping("/admin/task/selectDate/{id}")
    public Result seletDateTask(@PathVariable Integer id) {
        log.info("查看打卡对象详情：{}", id);
        List<StudentTask> studentHomeWorkList = adminService.selectDateTask(id);
        return Result.success(studentHomeWorkList);
    }

    @PutMapping("/admin/task/add")
    public Result addTask(@RequestBody Task task) {
        log.info("添加打卡对象：{}", task);
        adminService.addTask(task);
        return Result.success();
    }

    @PostMapping("/admin/task/delet")
    public Result delTask(@RequestBody Task task) {
        log.info("删除打卡对象{}", task);
        adminService.delTask(task);
        return Result.success();
    }

    @GetMapping("/admin/data")
    public Result allData() {
        log.info("查询首页展示数据");
        IndexDataAll indexDataAll = adminService.allData();
        return Result.success(indexDataAll);
    }

    @PutMapping("/admin/announ/add")
    public Result addAnnoun(@RequestBody Announcemen announcemen) {
        log.info("添加公告对象：{}", announcemen);
        adminService.addAnnoun(announcemen);
        return Result.success();
    }

    @GetMapping("/admin/showAnnoun")
    public Result getAllAnnoun() {

        log.info("查询所有符合的公告");
        List<Announcemen> announcemenList = adminService.getAllAnnoun();

        return Result.success(announcemenList);

    }

    @GetMapping("/admin/username")
    public Result getName(@RequestParam String username) {

        log.info("查询登录人姓名：{}", username);
        Teacher teacher = adminService.getName(username);

        return Result.success(teacher);

    }


    @PutMapping("/admin/test/add")
    public Result addTest(@RequestBody Test test) {
        log.info("添加公告对象：{}", test);
        adminService.addTest(test);
        return Result.success();
    }

    @GetMapping("/admin/showTest")
    public Result getAllTest() {

        log.info("查询所有符合的公告");
        List<Test> testList = adminService.getTest();

        return Result.success(testList);

    }


}
